from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-06-29 14:02:32.967912
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 29, Jun, 2022
Time: 14:02:38
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.6357
Nobs: 702.000 HQIC: -49.9939
Log likelihood: 8752.22 FPE: 1.54853e-22
AIC: -50.2196 Det(Omega_mle): 1.36343e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.297878 0.057701 5.162 0.000
L1.Burgenland 0.107390 0.037902 2.833 0.005
L1.Kärnten -0.109506 0.020066 -5.457 0.000
L1.Niederösterreich 0.212575 0.079162 2.685 0.007
L1.Oberösterreich 0.103491 0.077628 1.333 0.182
L1.Salzburg 0.257137 0.040532 6.344 0.000
L1.Steiermark 0.045507 0.052793 0.862 0.389
L1.Tirol 0.109324 0.042850 2.551 0.011
L1.Vorarlberg -0.059344 0.037180 -1.596 0.110
L1.Wien 0.040916 0.068681 0.596 0.551
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.049865 0.121033 0.412 0.680
L1.Burgenland -0.034153 0.079503 -0.430 0.668
L1.Kärnten 0.041171 0.042089 0.978 0.328
L1.Niederösterreich -0.168587 0.166049 -1.015 0.310
L1.Oberösterreich 0.424901 0.162832 2.609 0.009
L1.Salzburg 0.289077 0.085020 3.400 0.001
L1.Steiermark 0.100607 0.110739 0.909 0.364
L1.Tirol 0.319016 0.089882 3.549 0.000
L1.Vorarlberg 0.028166 0.077989 0.361 0.718
L1.Wien -0.042706 0.144065 -0.296 0.767
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186775 0.029537 6.323 0.000
L1.Burgenland 0.090308 0.019402 4.655 0.000
L1.Kärnten -0.008016 0.010271 -0.780 0.435
L1.Niederösterreich 0.266051 0.040522 6.566 0.000
L1.Oberösterreich 0.136869 0.039737 3.444 0.001
L1.Salzburg 0.045941 0.020748 2.214 0.027
L1.Steiermark 0.020080 0.027025 0.743 0.457
L1.Tirol 0.091609 0.021935 4.176 0.000
L1.Vorarlberg 0.056494 0.019032 2.968 0.003
L1.Wien 0.115153 0.035157 3.275 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111930 0.030055 3.724 0.000
L1.Burgenland 0.045628 0.019742 2.311 0.021
L1.Kärnten -0.013800 0.010452 -1.320 0.187
L1.Niederösterreich 0.192270 0.041233 4.663 0.000
L1.Oberösterreich 0.301646 0.040434 7.460 0.000
L1.Salzburg 0.108223 0.021112 5.126 0.000
L1.Steiermark 0.105125 0.027499 3.823 0.000
L1.Tirol 0.103787 0.022320 4.650 0.000
L1.Vorarlberg 0.067428 0.019366 3.482 0.000
L1.Wien -0.022990 0.035774 -0.643 0.520
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.134129 0.054871 2.444 0.015
L1.Burgenland -0.051451 0.036043 -1.427 0.153
L1.Kärnten -0.044377 0.019081 -2.326 0.020
L1.Niederösterreich 0.156971 0.075279 2.085 0.037
L1.Oberösterreich 0.139661 0.073820 1.892 0.059
L1.Salzburg 0.286611 0.038544 7.436 0.000
L1.Steiermark 0.047107 0.050204 0.938 0.348
L1.Tirol 0.166995 0.040749 4.098 0.000
L1.Vorarlberg 0.093311 0.035357 2.639 0.008
L1.Wien 0.073363 0.065312 1.123 0.261
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054580 0.043620 1.251 0.211
L1.Burgenland 0.037756 0.028653 1.318 0.188
L1.Kärnten 0.051075 0.015169 3.367 0.001
L1.Niederösterreich 0.217811 0.059844 3.640 0.000
L1.Oberösterreich 0.294623 0.058685 5.020 0.000
L1.Salzburg 0.047585 0.030641 1.553 0.120
L1.Steiermark 0.001690 0.039910 0.042 0.966
L1.Tirol 0.140625 0.032394 4.341 0.000
L1.Vorarlberg 0.073761 0.028107 2.624 0.009
L1.Wien 0.081409 0.051921 1.568 0.117
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.175431 0.052174 3.362 0.001
L1.Burgenland -0.002358 0.034272 -0.069 0.945
L1.Kärnten -0.063023 0.018144 -3.474 0.001
L1.Niederösterreich -0.081034 0.071580 -1.132 0.258
L1.Oberösterreich 0.194533 0.070193 2.771 0.006
L1.Salzburg 0.056525 0.036650 1.542 0.123
L1.Steiermark 0.236221 0.047737 4.948 0.000
L1.Tirol 0.497605 0.038746 12.843 0.000
L1.Vorarlberg 0.044877 0.033619 1.335 0.182
L1.Wien -0.056249 0.062103 -0.906 0.365
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.169289 0.059309 2.854 0.004
L1.Burgenland -0.012634 0.038958 -0.324 0.746
L1.Kärnten 0.063837 0.020625 3.095 0.002
L1.Niederösterreich 0.206978 0.081368 2.544 0.011
L1.Oberösterreich -0.078221 0.079791 -0.980 0.327
L1.Salzburg 0.213038 0.041662 5.114 0.000
L1.Steiermark 0.125986 0.054265 2.322 0.020
L1.Tirol 0.067022 0.044045 1.522 0.128
L1.Vorarlberg 0.119293 0.038216 3.122 0.002
L1.Wien 0.127807 0.070595 1.810 0.070
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.363516 0.034309 10.596 0.000
L1.Burgenland 0.007543 0.022536 0.335 0.738
L1.Kärnten -0.023613 0.011931 -1.979 0.048
L1.Niederösterreich 0.216218 0.047069 4.594 0.000
L1.Oberösterreich 0.204774 0.046157 4.436 0.000
L1.Salzburg 0.044022 0.024100 1.827 0.068
L1.Steiermark -0.014059 0.031391 -0.448 0.654
L1.Tirol 0.105746 0.025478 4.150 0.000
L1.Vorarlberg 0.069059 0.022107 3.124 0.002
L1.Wien 0.029082 0.040837 0.712 0.476
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037667 0.137011 0.193762 0.155322 0.114989 0.101673 0.058086 0.217578
Kärnten 0.037667 1.000000 -0.015149 0.134154 0.056017 0.095387 0.435758 -0.053133 0.093591
Niederösterreich 0.137011 -0.015149 1.000000 0.335739 0.141728 0.294309 0.092169 0.177104 0.310951
Oberösterreich 0.193762 0.134154 0.335739 1.000000 0.226711 0.325020 0.176095 0.164226 0.265302
Salzburg 0.155322 0.056017 0.141728 0.226711 1.000000 0.138139 0.116493 0.138754 0.130754
Steiermark 0.114989 0.095387 0.294309 0.325020 0.138139 1.000000 0.145698 0.129414 0.073504
Tirol 0.101673 0.435758 0.092169 0.176095 0.116493 0.145698 1.000000 0.113036 0.141601
Vorarlberg 0.058086 -0.053133 0.177104 0.164226 0.138754 0.129414 0.113036 1.000000 0.005341
Wien 0.217578 0.093591 0.310951 0.265302 0.130754 0.073504 0.141601 0.005341 1.000000